﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.IO;
using System.Windows.Forms;

namespace RSHB.Framework.BLL
{
    public abstract class RTFFileContentBuilder : IFileContentBuilder
    {
        protected RichTextBox rtb = new RichTextBox();

        protected abstract void ProcessDocument();

        public virtual MemoryStream Build(Stream fileContent)
        {
            using (TextReader tr = new StreamReader(fileContent))
            {
                this.rtb.Rtf = tr.ReadToEnd();                
            }

            this.ProcessDocument();
            
            MemoryStream stream = new MemoryStream();
            byte[] buffer = new byte[rtb.Rtf.Length];
            buffer = Encoding.UTF8.GetBytes(rtb.Rtf);
            stream.Write(buffer, 0, buffer.Length);

            return stream;
        }
    }
}
